package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static org.jsola.core.example.BaseExample.*;
import static org.jsola.hr.example.AttendPlanExample.*;

/**
 * 考勤方案
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class AttendPlanQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = N_COMPANY_ID, example = E_COMPANY_ID)
    @Length(max = 32)
    private String companyId;

    @ApiParam(value = N_COMPANY_NAME, example = E_COMPANY_NAME)
    @Length(max = 100)
    private String companyName;

    @ApiParam(value = N_NAME, example = E_NAME)
    @Length(max = 100)
    private String name;

    @ApiParam(value = N_PLAN_TYPE, example = E_PLAN_TYPE)
    private Integer planType;

    @ApiParam(value = N_PUNCH_LOCATION_JSON, example = E_PUNCH_LOCATION_JSON)
    @Length(max = 65535)
    private String punchLocationJson;

    @ApiParam(value = N_PUNCH_WIFI_JSON, example = E_PUNCH_WIFI_JSON)
    @Length(max = 65535)
    private String punchWifiJson;

    @ApiParam(value = N_OVERTIME_RULE, example = E_OVERTIME_RULE)
    private Integer overtimeRule;

    @ApiParam(value = N_IS_SYNCH_LEGAL_HOLIDAY, example = E_IS_SYNCH_LEGAL_HOLIDAY)
    private Boolean isSynchLegalHoliday;

    @ApiParam(value = N_IS_REMIND, example = E_IS_REMIND)
    private Boolean isRemind;

    @ApiParam(value = N_REMIND_BEFORE, example = E_REMIND_BEFORE)
    private Integer remindBefore;

    @ApiParam(value = N_REMIND_AFTER, example = E_REMIND_AFTER)
    private Integer remindAfter;

    @ApiParam(value = N_IS_TAKE_PHOTO, example = E_IS_TAKE_PHOTO)
    private Boolean isTakePhoto;

    @ApiParam(value = N_IS_ONLY_PHOTO, example = E_IS_ONLY_PHOTO)
    private Boolean isOnlyPhoto;

    @ApiParam(value = N_PUNCH_RANGE, example = E_PUNCH_RANGE)
    private Integer punchRange;

    @ApiParam(value = N_IS_MAKE_UP, example = E_IS_MAKE_UP)
    private Boolean isMakeUp;

    @ApiParam(value = N_MAX_MAKE_UP_COUNTS, example = E_MAX_MAKE_UP_COUNTS)
    private Integer maxMakeUpCounts;

    @ApiParam(value = N_TAKE_EFFECT, example = E_TAKE_EFFECT)
    private Integer takeEffect;

    @ApiParam(value = "主键集合", example = "")
    private List<String> ids;

    @ApiParam(value = N_START_EFFECT_TIME, example = E_START_EFFECT_TIME)
    private Date startEffectTime;

    /**
     * 创建时间查询范围
     */
    @ApiParam(value = N_GMT_CREATE_START, example = E_GMT_CREATE_START)
    private Date gmtCreateStart;
    @ApiParam(value = N_GMT_CREATE_END, example = E_GMT_CREATE_END)
    private Date gmtCreateEnd;


    @ApiParam(value = N_CREATE_USER_ID, example = E_CREATE_USER_ID)
    @Length(max = 32)
    private String createUserId;

    /**
     * 修改时间查询范围
     */
    @ApiParam(value = N_GMT_MODIFIED_START, example = E_GMT_MODIFIED_START)
    private Date gmtModifiedStart;
    @ApiParam(value = N_GMT_MODIFIED_END, example = E_GMT_MODIFIED_END)
    private Date gmtModifiedEnd;


    @ApiParam(value = N_MODIFIED_USER_ID, example = E_MODIFIED_USER_ID)
    @Length(max = 32)
    private String modifiedUserId;



    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public AttendPlanQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

}

